#include "stdafx.h"
#include "ui_title.h"
#include <WindowsX.h>

_SSL_BEGIN
_SSUIL_BEGIN

UITitle::UITitle()
{
	background_transparent_ = true;
}

UITitle::~UITitle()
{

}

void UITitle::OnWindowManagerChangedCB(IUIManagerInterface *old_manager, IUIManagerInterface *new_manager)
{
	if(old_manager != NULL)
		old_manager->RemoveMessageFilter(this);
	if(new_manager != NULL)
		new_manager->AppendMessageFilter(this);
}

LRESULT UITitle::MessageHandle(
	IUIManagerInterface *manager,
	UINT msg,
	WPARAM wparam,
	LPARAM lparam,
	bool &handled
	)
{
	handled = false;
	if(msg != WM_NCHITTEST)
		return 0L;

	scoped_ref_ptr<IUIManagerInterface> win_man = GetWindowManager();
	if(win_man == NULL)
		return 0L;

	scoped_ref_ptr<IUIControlInterface> root = win_man->GetContent();
	if(root == NULL)
		return 0L;

	UIPoint cursor_point(GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
	::MapWindowPoints(NULL, win_man->GetWindow(), &cursor_point, 1);

	if(!::PtInRect(&GetVisiblePositionOnClient(), cursor_point))
		return 0L;

	UIFindControlByPoint find_data;
	find_data.pt = cursor_point;
	find_data.for_press = true;
	if(root->FindControl(find_data)  != NULL)
		return 0L;

	handled = true;
	return HTCAPTION;
}

_SSUIL_END
_SSL_END
